package com.think.teaching.service.impl;

import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.think.teaching.mapper.CourseHistoryMapper;
import com.think.teaching.model.CourseHistory;

@Service
public class CourseHistoryService extends BaseServiceImpl<CourseHistoryMapper, CourseHistory> {
	
	
	public IPage<Map<String, Object>> ListHistorys(Integer page,Integer count,Integer courseId){
		IPage<Map<String, Object>> ipage = new Page<Map<String,Object>>(page,count);
		return baseMapper.ListHistorys(ipage, courseId);
	}
	
	public Integer GetChapterVisitCount(Integer chapterId) {
		QueryWrapper<CourseHistory> queryWrapper = new QueryWrapper<CourseHistory>();
		queryWrapper.eq("chapter_id", chapterId);
		return this.count(queryWrapper);
	}
	
	public Integer GetChapterVisitStudentCount(Integer chapterId) {
		QueryWrapper<CourseHistory> queryWrapper = new QueryWrapper<CourseHistory>();
		queryWrapper.eq("chapter_id", chapterId).groupBy("user_id").select("user_id");
		return this.list(queryWrapper).size();
	}
	
	public Integer GetCourseVisitCount(Integer courseId) {
		QueryWrapper<CourseHistory> queryWrapper = new QueryWrapper<CourseHistory>();
		queryWrapper.eq("course_id", courseId);
		return this.count(queryWrapper);
	}
	
	public Integer GetCourseVisitStudentCount(Integer courseId) {
		QueryWrapper<CourseHistory> queryWrapper = new QueryWrapper<CourseHistory>();
		queryWrapper.eq("course_id", courseId).groupBy("user_id").select("user_id");
		return this.list(queryWrapper).size();
	}
}
